<template>
  <div class="default-main ba-table-box">
    <div class="block">
      <div class="table-block">
        <el-alert class="ba-table-alert"
                  v-if="baTable.table.remark"
                  :title="baTable.table.remark"
                  type="info"
                  show-icon />
        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
                     :quick-search-placeholder="t('Quick search placeholder', { fields: '订单号' })">
          <template #status>
            <el-switch v-model="baTable.comSearch.form['status']" />
          </template>
        </TableHeader>
        <Table></Table>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, provide } from 'vue'
import baTableClass from '/@/utils/baTable'
// import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { baTableApi } from '/@/api/common'
import Cookies from 'js-cookie'
import { useI18n } from 'vue-i18n'
import { defaultOptButtons } from '/@/components/table'
import { concat } from 'lodash-es'
import { useAdminInfo } from '/@/stores/adminInfo'

defineOptions({
    name: 'warehouse/tikinventory',
})
const { t } = useI18n()
const state: {
    buttonLoading: boolean
} = reactive({
    buttonLoading: false
})
const adminInfo = useAdminInfo()
let optButtons: OptButton[] = [
    {
        render: 'tipButton',
        name: '更新',
        title: '',
        text: '更新',
        type: 'primary',
        icon: '',
        class: 'table-row-info',
        disabledTip: false,
        click: (row: TableRow) => {
            console.log(row)
        }
    }
]
optButtons = concat(defaultOptButtons(['edit', 'delete']), optButtons)
optButtons[1].display = (row) => {
    return row.id != adminInfo.id
}
const baTable = new baTableClass(
    new baTableApi('/warehouse/tikinventory/'),
    {
        column: [
            {
                label: '店铺',
                prop: 'shop_name_arr',
                align: 'center',
                comSearchRender: 'remoteSelect',
                remote: {
                    pk: 'id',
                    field: 'name',
                    remoteUrl: '/shop/shop/index',
                    params: { select: true },
                },
            },
            {   
                label: '产品ID', 
                prop: 'product_id', 
                align: 'center',
                operatorPlaceholder: t('Please input field')
            },
            {   
                label: 'sku', 
                prop: 'sku_info', 
                align: 'center',
                operatorPlaceholder: t('Please input field')
            },
            {   
                label: '库存', 
                prop: 'inventory', 
                align: 'center',
                operator: false
            },
            {
                label: t('Operate'),
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: optButtons,
                operator: false,
            }
        ],
        dblClickNotEditColumn: ['all']
    },
    {
        defaultItems: {
            status: '1',
        }
    }
)

provide('baTable', baTable)

baTable.mount()
baTable.getIndex()

</script>

<style scoped lang="scss">
</style>
